using System;

namespace OpenXmlWriter.Packaging
{
  public class PartsFactory
  {
    private OpenXmlPartContainer _openXmlPartContainer;
    private OpenXmlPackage _openXmlPackage;

    public PartsFactory(OpenXmlPackage openXmlPackage, OpenXmlPartContainer openXmlPartContainer)
    {
      _openXmlPackage = openXmlPackage;
      _openXmlPartContainer = openXmlPartContainer;
    }

    public OpenXmlPart CreatePart(Type partType)
    {
      OpenXmlPart part = (OpenXmlPart) Activator.CreateInstance(partType, true);
      part.Initialize(_openXmlPackage, _openXmlPartContainer);
      return part;
    }

    public OpenXmlPackage OpenXmlPackage
    {
      get
      {
        return _openXmlPackage;
      }
      set
      {
        _openXmlPackage = value;
      }
    }
  }
}